package com.android.welcome;
import com.ainput.girlfriend.MainActivity;
import com.android.activity.BaseActivity;
import com.ainput.girlfriend.R;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class WelcomeActivity extends BaseActivity{

	private AlphaAnimation anim;
	private RelativeLayout rl_welcome;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	@Override
	protected void installViews() {
		// TODO Auto-generated method stub
		initControls();
		initOpenAnim();
	}
	private void initOpenAnim() {
		// TODO Auto-generated method stub
		float fromAlpha = 0.1f;
		float toAlpha = 1.0f;
		anim = new AlphaAnimation(fromAlpha, toAlpha);
		anim.setDuration(2 * 1000);
		rl_welcome.startAnimation(anim);
	}
	@SuppressWarnings("deprecation")
	private void initControls() {
		// TODO Auto-generated method stub
		rl_welcome = new RelativeLayout(this);
		rl_welcome.setBackgroundDrawable(new BitmapDrawable(getResources()
				.openRawResource(R.drawable.welcome)));
		rl_welcome.setLayoutParams(new RelativeLayout.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		setContentView(rl_welcome);
	}
	@Override
	protected void registerEvents() {
		// TODO Auto-generated method stub
		anim.setAnimationListener(new WelcomeAnimListerner());
	}
	private class WelcomeAnimListerner implements Animation.AnimationListener {

		@Override
		public void onAnimationStart(Animation animation) {

		}

		@Override
		public void onAnimationRepeat(Animation animation) {

		}

		@Override
		public void onAnimationEnd(Animation animation) {
			MainActivity.launch(mContext);
			finish();

		}
	}
}
